<%@ page import="org.springframework.jdbc.core.BeanPropertyRowMapper" %>
<%@ page import="com.cinsea.directory.model.Directory" %>
<%@ page import="com.cinsea.directory.service.DirectoryService" %>
<%@ page import="com.cinsea.workflow.service.WfnodeService" %>
<%@ page import="com.cinsea.workflow.service.WfdefineService" %>
<%@ page import="com.cinsea.htmlselect.model.Option" %>
<%@ page import="com.cinsea.notify.model.Notifysetting" %>
<%@ page import="com.cinsea.security.model.*" %>
<%@ page import="com.cinsea.security.service.RightService" %>
<%@ page import="com.cinsea.report.service.ReportService" %>
<%@ page import="com.cinsea.form.model.Formfield" %>
<%@ page import="com.cinsea.form.model.Formview" %>
<%@ page import="com.cinsea.form.service.FormviewService" %>
<%@ page import="com.cinsea.hrm.model.*" %>
<%@ page import="com.cinsea.workflow.model.Wfnode" %>
<%@ page import="com.cinsea.form.model.Formrelationship" %>
<%@ page import="com.cinsea.security.util.HibernateUtil" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/common.jsp" %>


<%
    response.setHeader("cache-control", "no-cache");
    response.setHeader("pragma", "no-cache");
    response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
    RightService rightService = (RightService) Env.getBean("rightService");
    NotifysettingService notifysettingServicevice = (NotifysettingService) Env.getBean("notifysettingService");
    HumanService humanService = (HumanService) Env.getBean("humanService");
    WfnodeService wfnodeService = (WfnodeService) Env.getBean("wfnodeService");
    WfdefineService wfdefineService = (WfdefineService) Env.getBean("wfdefineService");
    FormfieldService formfieldService = (FormfieldService) Env.getBean("formfieldService");
    FormService formService = (FormService) Env.getBean("formService");
    JdbcDao jdbcDao = (JdbcDao) Env.getBean("jdbcDao");
    OrgtypeService orgtypeService = (OrgtypeService) Env.getBean("orgtypeService");
    OrgService orgService = (OrgService) Env.getBean("orgService");
    RoleService roleService = (RoleService) Env.getBean("roleService");
    DirectoryService directoryService = (DirectoryService) Env.getBean("directoryService");
    NotifysettingService notifysettingService = (NotifysettingService) Env.getBean("notifysettingService");
    FormrelationshipService formrelationshipService = (FormrelationshipService) Env.getBean("formrelationshipService");
    String objid = StringUtil.null2String(request.getParameter("objid"));
    String formid = StringUtil.null2String(request.getParameter("formid"));
    String tablename = StringUtil.null2String(request.getParameter("tablename")).trim();
    if (StringUtil.isEmpty(tablename) && !StringUtil.isEmpty(formid)) {
        tablename = formService.getFormById(formid).getTablename();
    }

    String beworkflow = StringUtil.null2String(request.getParameter("beworkflow")).trim();
    String nodeid = StringUtil.null2String(request.getParameter("nodeid")).trim();


    int betype = NumberUtil.string2Int(request.getParameter("betype"), 0);
    /*if (!(betype == 1)) {
        Env.setTablename(tablename);
        boolean opttype = rightService.checkOpttype(objid, 375);
        if (!opttype) {
            response.sendRedirect(request.getContextPath() + "/nopermit.jsp");
            return;
        }
    }*/


    int nodetype = 0;
    int betypeof = 0;
    if (beworkflow.equalsIgnoreCase("1")) nodetype = 2;
    if (betype == 1 && beworkflow.equalsIgnoreCase("1")) {
        betypeof = 1; //工作流类型权限；
        formid = wfdefineService.get(objid).getFormid();
    }
    if (betype == 1 && beworkflow.equalsIgnoreCase("1") && !StringUtil.isEmpty(nodeid)) {
        betypeof = 1; //工作流类型权限；

        Wfnode wfnode = wfnodeService.get(nodeid);
        nodetype = wfnode.getObjtype().intValue();
        formid = wfdefineService.get(wfnode.getWorkflowid()).getFormid();


    }
    if (tablename.equalsIgnoreCase("cs_document")) {
        betypeof = 2; //文档类型权限；

    }
    Boolean hasCondition = false;
    String dowid = "";
    if (betype == 0 && !beworkflow.equalsIgnoreCase("1") && !HibernateUtil.isRightBean(tablename)) {
        String sql = "";
        List list = new ArrayList();
        sql = "select dowid from " + tablename + " t1 where  id=?";
        list = jdbcDao.getJdbcTemplate().queryForList(sql, new Object[]{objid});
        if (list.size() != 0) {
            Map map = (Map) list.get(0);
            dowid = StringUtil.null2String(map.get("dowid"));
        }


        List<Right> originrules = rightService.find("select * from cs_right t1 where betype='1' and t1.objid=?", new Object[]{dowid});


        if (originrules.size() != 0) {
            for (Right rule : originrules) {
                if (rule.getOpttype() != 2) {
                    if (rule.getCondition() != null && !"".equals(rule.getCondition())) {
                        hasCondition = true;
                        break;
                    }
                }
            }
        }
    }

    pagemenustr += "addBtn(tb,'" + I18n.getText("add") + "','S','accept');";
    /*if (betype == 0)
        pagemenustr += "addBtn(tb,'" + I18n.getText("rightrefactor") + "','C','accept');";
    if (betype == 1 && !beworkflow.equals("1") && !tablename.equals("doctype"))
        pagemenustr += "addBtn(tb,'" + I18n.getText("historydata") + I18n.getText("rightrefactor") + "','H','accept');";

    if (betype == 1 && beworkflow.equals("1"))
        pagemenustr += "addBtn(tb,'" + I18n.getText("historydata") + I18n.getText("rightrefactor") + "','G','accept');";*/
    pagemenustr += "addBtn(tb,'" + I18n.getText("delete") + "','D','delete');";
    //data prepare
    String rightrangestr = "";
    List<Option> options = optionService.getOptions2("6", null);
    for (Option option : options) {
        rightrangestr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(rightrangestr)) {
        rightrangestr = rightrangestr.substring(1);
    }
    String dimensionstr = "";
    options = optionService.getOptions2("1", null);
    for (Option option : options) {

        dimensionstr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(dimensionstr)) {
        dimensionstr = dimensionstr.substring(1);
    }
    boolean beone=false;
    if(options.size()==1) beone=true;
    String orgwherestr = "";
    options = optionService.getOptions2("10", null);
    for (Option option : options) {
        //非工作流相关不显示工作流节点
        if (!option.getId().equals("31"))
            continue;
        orgwherestr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(orgwherestr)) {
        orgwherestr = orgwherestr.substring(1);
    }
    String userwherestr = "";
    options = optionService.getOptions2("9", null);
    for (Option option : options) {
        if (!option.getId().equalsIgnoreCase("26"))
            continue;
        userwherestr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(userwherestr)) {
        userwherestr = userwherestr.substring(1);
    }
    String postwherestr = "";
    options = optionService.getOptions2("17", null);
    for (Option option : options) {
        if (! option.getId().equalsIgnoreCase("59"))
            continue;
        postwherestr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(postwherestr)) {
        postwherestr = postwherestr.substring(1);
    }

    String nodeforworkitemstr = "";
    if (betypeof == 1 && !beworkflow.equals("1")) {
        List<Wfnode> nodelist = wfnodeService.getNodesByWorkflowid(objid);
        for (int i = 0; i < nodelist.size(); i++) {
            Wfnode _wfnode = nodelist.get(i);
            nodeforworkitemstr += ",['" + _wfnode.getId() + "','" + StringUtil.null2String(_wfnode.getObjname()) + "']";
        }
    } else if (betypeof == 1 && beworkflow.equals("1")) {
        List list = wfnodeService.getNodesByWorkflowid(objid);
        for (int i = 0; i < list.size(); i++) {
            Wfnode _wfnode = (Wfnode) list.get(i);
            nodeforworkitemstr += ",['" + _wfnode.getId() + "','" + StringUtil.null2String(_wfnode.getObjname()) + "']";
        }
    }
    if (!StringUtil.isEmpty(nodeforworkitemstr)) {
        nodeforworkitemstr = nodeforworkitemstr.substring(1);
    }
    String orgrangestr = "";
    options = optionService.getOptions2("11", null);
    for (Option option : options) {
        orgrangestr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname() )+ "']";
    }
    if (!StringUtil.isEmpty(orgrangestr)) {
        orgrangestr = orgrangestr.substring(1);
    }
    String rolewherestr = "";
    options = optionService.getOptions2("20", null);
    for (Option option : options) {
        if (! option.getId().equalsIgnoreCase("69"))
                    continue;
        rolewherestr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(rolewherestr)) {
        rolewherestr = rolewherestr.substring(1);
    }
    String postrangestr = "";
    options = optionService.getOptions2("18", null);
    for (Option option : options) {
        postrangestr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(postrangestr)) {
        postrangestr = postrangestr.substring(1);
    }
    String postlevelstr = "";
    options = optionService.getOptions2("19", null);
    for (Option option : options) {
        postlevelstr += ",['" + option.getId() + "','" + I18n.getText(option.getObjname()) + "']";
    }
    if (!StringUtil.isEmpty(postlevelstr)) {
        postlevelstr = postlevelstr.substring(1);
    }
    String orgtypestr = "";
    List<Orgtype> orgtypes = orgtypeService.getOrgtypeList();
    for (Orgtype orgtype : orgtypes) {
        orgtypestr += ",['" + orgtype.getId() + "','" + orgtype.getObjname() + "']";
    }
    if (!StringUtil.isEmpty(orgtypestr)) {
        orgtypestr = orgtypestr.substring(1);
    }
    String opttypestr = "";
    String opttypeparam=StringUtil.null2String(request.getParameter("opttype"));
    if(opttypeparam.equals("1493"))
    opttypestr="['1493','投票']";
    else if(opttypeparam.equals("1499"))
    opttypestr="['1499','结果查看']";
    else
    return;
    String attachopttypestr = "";
    //附件操作类型
    if (betypeof == 2) {
        options = optionService.getOptions2("13", null);
        for (Option option : options) {
            attachopttypestr += ",['" + option.getObjdesc() + "','" + I18n.getText(option.getObjname()) + "']";
        }
        if (!StringUtil.isEmpty(attachopttypestr)) {
            attachopttypestr = attachopttypestr.substring(1);
        }
    }
    String wfopttypestr = "";
    // 流程活动节点操作类型
    if (betypeof == 1 && nodetype != 1 && nodetype != 4 && beworkflow.equals("1")) {
        options = optionService.getOptions2("14", null);
        for (Option option : options) {
            wfopttypestr += ",['" + option.getObjdesc() + "','" + I18n.getText(option.getObjname()) + "']";
        }
        if (!StringUtil.isEmpty(wfopttypestr)) {
            wfopttypestr = wfopttypestr.substring(1);
        }
    }
    if (betypeof == 1 && nodetype == 4) {
        wfopttypestr = "['3','不知会'],['1','知会']";
    }
    List formfieldList;
    if ("cs_wfprocess".equals(tablename))
        formfieldList = formfieldService.getFieldsByMainformId(formid);
    else {
        Directory directory = directoryService.getDirectoryById(objid);
        while (StringUtil.isEmpty(directory.getFormid()) && !StringUtil.isEmpty(directory.getPid())) {
            directory = directoryService.getDirectoryById(directory.getPid());
        }
        formfieldList = formfieldService.getFieldsByMainformId(directory.getFormid());
    }


    String editviewstr = "";
    String readviewstr = "";
    String notifysettingstr= null;
    if (!StringUtil.isEmpty(formid)) {
        String strDefHql = "from Formview where formid='" + formid + "'";
        FormviewService formviewService = (FormviewService) Env.getBean("formviewService");
        List listdef = formviewService.findFormview(strDefHql);
        List layoutlist = new ArrayList();
        layoutlist.addAll(listdef);
        for (int i = 0; i < layoutlist.size(); i++) {
            Formview formview = (Formview) layoutlist.get(i);
            if (formview.getTypeid().intValue() == 2)
                editviewstr += ",['" + formview.getId() + "','" + formview.getObjname() + "']";
            if (formview.getTypeid().intValue() == 1)
                readviewstr += ",['" + formview.getId() + "','" + formview.getObjname() + "']";
        }
        if (!StringUtil.isEmpty(editviewstr)) {
            editviewstr = editviewstr.substring(1);
        }
        if (!StringUtil.isEmpty(readviewstr)) {
            readviewstr = readviewstr.substring(1);
        }
        Form form=formService.get(formid);
        String hql;
        if(form.getObjtype()==0)
          hql = "from Notifysetting where formid='"+formid+"'";
        else{
          List<Formrelationship> slaves = formrelationshipService.find("from Formrelationship where hostid='" + formid + "' and typeid=1");
            String slaveidstr="";
                for (Formrelationship fls:slaves ) {
                    String slaveid = fls.getSlaveid();
                    if(StringUtil.isEmpty(slaveidstr)) slaveidstr=slaveidstr+"'"+slaveid+"'";
                    else slaveidstr=slaveidstr+",'"+slaveid+"'";
                }
            hql = "from Notifysetting where formid in("+slaveidstr+")";
        }
        List notifysettinglist = notifysettingService.find(hql);
        notifysettingstr = "";
        for (int i = 0; i < notifysettinglist.size(); i++) {
            Notifysetting notifysetting = (Notifysetting) notifysettinglist.get(i);
            notifysettingstr += ",['" + notifysetting.getId() + "','" + notifysetting.getObjname() + "']";
        }
        if (!StringUtil.isEmpty(notifysettingstr)) {
            notifysettingstr = notifysettingstr.substring(1);
        }
    }

%>
<html>
<head>

<%@ include file="/common/head.jsp" %>
<base target=_self></base>
<script src='${ctx}/dwr/interface/RightTransferService.js'></script>
<script type="text/javascript">
var selected = new Array();
var total = 0;
var currentCount = 0;
var refresstimer;
var pbar1;
var store;
Ext.onReady(function() {
    var tb = new Ext.Toolbar();
    tb.render('pagemenubar');
    <%=pagemenustr%>
    var btnS = Ext.getCmp('S');
    var btnC = Ext.getCmp('C');
    var btnD = Ext.getCmp('D');
    var btnH = Ext.getCmp('H');
    var btnG = Ext.getCmp('G');
    var btnR = Ext.getCmp('R');

    <%if(betype==1&&beworkflow.equals("1")){%>
    pbar1 = new Ext.ProgressBar({
        text:''
    });
    if (btnG)
        btnG.on('click', function() {
            total = 0;
            currentCount = 0;
            if (btnS)
                Ext.getCmp('S').disable();
            if (btnC)
                Ext.getCmp('C').disable();
            Ext.getCmp('G').disable();
            Ext.fly('p1').setDisplayed(true);
            if (!pbar1.rendered) {
                pbar1.render(p1);
            } else {
                pbar1.text = '';
                pbar1.show();
            }
            doRefactorWorkflowinfo('<%=objid%>');
            if (total == -1) {
                pbar1.reset(true);
                if (btnS)
                    Ext.getCmp('S').enable();
                if (btnC)
                    Ext.getCmp('C').enable();
                Ext.getCmp('G').enable();
                pop('请等待先前的任务完成');
                return;
            }
            if (total == 0) {
                pbar1.reset(true);
                Ext.getCmp('S').enable();
                if (btnC)
                Ext.getCmp('C').enable();
                Ext.getCmp('G').enable();
                pop('没有历史数据存在!');
                return;
            }
            Runner.run(pbar1, total, function() {
                pbar1.reset(true);
                pop('重构完成!');
            });
        });
    <%}%>
    <%if(betype==1&&!beworkflow.equals("1")&&!tablename.equals("document")){%>
    //==== Progress bar1  ====
    pbar1 = new Ext.ProgressBar({
        text:''
    });
    if (btnH)
        btnH.on('click', function() {
            total = 0;
            currentCount = 0;
            if (btnS)
                Ext.getCmp('S').disable();
            if (btnC)
                Ext.getCmp('C').disable();
            Ext.getCmp('H').disable();
            Ext.fly('p1').setDisplayed(true);
            if (!pbar1.rendered) {
                pbar1.render(p1);
            } else {
                pbar1.text = '';
                pbar1.show();
            }
            doRefactor('<%=objid%>', '<%=tablename%>');
            if (total == -1) {
                pbar1.reset(true);
                if (btnS)
                    Ext.getCmp('S').enable();
                if (btnC)
                    Ext.getCmp('C').enable();
                Ext.getCmp('H').enable();
                pop('请等待先前的任务完成');
                return;
            }
            if (total == 0) {
                pbar1.reset(true);
                if (btnS)
                    Ext.getCmp('S').enable();
                if (btnC)
                    Ext.getCmp('C').enable();
                Ext.getCmp('H').enable();
                pop('重构完成');
                return;
            }
            Runner.run(pbar1, total, function() {
                pbar1.reset(true);
                pop('重构完成');
            });
        });
    <%}%>
    btnS.on('click', function() {
        onCreate();
    });
    btnD.on('click', function() {
        onDelete();
    });
    if (btnC)
        btnC.on('click', function() {
            if (btnH)
                Ext.getCmp('H').disable();
            Ext.getCmp('C').disable();
            Ext.getCmp('S').disable();
            recreate();
        });
    <%if(betype==0&&!tablename.equals("document")&&hasCondition){%>
    //==== Progress bar1  ====
    pbar1 = new Ext.ProgressBar({
        text:''
    });
    if (btnR)
        btnR.on('click', function() {
            total = 0;
            currentCount = 0;
            Ext.getCmp('S').disable();
            if (btnC)
                Ext.getCmp('C').disable();
            Ext.fly('p1').setDisplayed(true);
            if (!pbar1.rendered) {
                pbar1.render(p1);
            } else {
                pbar1.text = '';
                pbar1.show();
            }
            doRequestRefactor('<%=objid%>', '<%=tablename%>');
            if (total == -1) {
                pbar1.reset(true);
                Ext.getCmp('S').enable();
                if (btnC)
                    Ext.getCmp('C').disable();
                pop('请等待先前的任务完成');
                return;
            }
            if (total == 0) {
                pbar1.reset(true);
                Ext.getCmp('S').enable();
                if (btnC)
                    Ext.getCmp('C').disable();
                pop('重构完成');
                return;
            }
            Runner.run(pbar1, total, function() {
                pbar1.reset(true);
                pop('重构完成!');
            });
        });
    <%}%>
    //grid
    store = new Ext.data.JsonStore({
        url: '${ctx}/ext/com.cinsea.ext.ResearchAction?action=getrights&opttype=<%=opttypeparam%>&objid=<%=objid%>&betype=<%=betype%>&beworkflow=<%=beworkflow%>&nodeid=<%=nodeid%>&tablename=<%=tablename%>&formid=<%=formid%>&nodetype=<%=nodetype%>' ,
        root: 'result',
        fields: ['opttype','rightrange','rightdesc','editview','readview','priority','betype','bedefault','id','condition']
    });
    var sm = new Ext.ux.grid.SelectiveCheckboxSelectionModel();
    var cm = new Ext.grid.ColumnModel([sm,
        {header: "<%=I18n.getText("permission")%><%=I18n.getText("type")%>",  sortable: false, width:100, dataIndex: 'rightrange',renderer:renderDesc},
        {header: "<%=I18n.getText("permission")%><%=I18n.getText("description")%>",  sortable: false, width:200,dataIndex: 'rightdesc',renderer:renderDesc}

    ]);
    cm.defaultSortable = true;
    function renderDesc(value, p, record) {
        p.attr = 'style="white-space:normal;word-break:break-all;line-height: 1.4"';
        return value;
    }

    var grid = new Ext.grid.GridPanel({
        region: 'center',
        store: store,
        cm: cm,
        trackMouseOver:false,
        sm:sm ,
        checkboxCondition: function(val, meta, record, rowIdx, colIdx, store) {
            if (record.data.betype == '0' && record.data.bedefault == '1')
                return false;
            else
                return true;
        },
        loadMask: true,
        bbar:pbar1,
        viewConfig: {
            forceFit:true,
            enableRowBody:true,
            sortAscText:'<%=I18n.getText("sortAscText")%>',
            sortDescText:'<%=I18n.getText("sortDescText")%>',
            columnsText:'<%=I18n.getText("columnsText")%>',
            getRowClass : function(record, rowIndex, p, store) {
                return 'x-grid3-row-collapsed';
            }
        }
    });

    store.on('load', function(st, recs) {
        for (var i = 0; i < recs.length; i++) {
            var reqid = recs[i].get('id');
            for (var j = 0; j < selected.length; j++) {
                if (reqid == selected[j]) {
                    sm.selectRecords([recs[i]], true);
                }
            }
        }
    }
            );
    sm.on('rowselect', function(selMdl, rowIndex, rec) {
        var reqid = rec.get('id');
        for (var i = 0; i < selected.length; i++) {
            if (reqid == selected[i]) {
                return;
            }
        }
        selected.push(reqid)
    }
            );
    sm.on('rowdeselect', function(selMdl, rowIndex, rec) {
        var reqid = rec.get('id');
        for (var i = 0; i < selected.length; i++) {
            if (reqid == selected[i]) {
                selected.remove(reqid)
                return;
            }
        }

    }
            );
    //Viewport
    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [
            {region:'north',autoScroll:true,contentEl:'divSearch'},
            grid
        ]
    });
    rightrangestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=rightrangestr%>]
    });
    //rolerange
    yesorno = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [
            ['1','<%=I18n.getText("yes")%>'],
            ['0','<%=I18n.getText("no")%>']
        ]
    });
    dimensionstore = new Ext.data.SimpleStore({
            id:0,
            fields: ['value', 'text'],
            data : [<%=dimensionstr%>]
        });
    orgwherestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=orgwherestr%>]
    });
    userwherestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=userwherestr%>]
    });
    postwherestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=postwherestr%>]
    });
    nodeforworkitemstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=nodeforworkitemstr%>]
    });
    fieldstore = new Ext.data.JsonStore({
        url:'${ctx}/formfield.do?action=getrightfields',
        root: 'result',
        fields: ['value', 'text']
    });
    rolefieldstore = new Ext.data.JsonStore({
        url:'${ctx}/formfield.do?action=getrightfields',
        root: 'result',
        fields: ['value', 'text']
    });
    orgrangestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=orgrangestr%>]
    });
    rolewherestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=rolewherestr%>]
    });

    postrangestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=postrangestr%>]
    });
    postlevelstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=postlevelstr%>]
    });
    orgtypestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=orgtypestr%>]
    });

    beorgmanagerstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [
            ['1','<%=I18n.getText("org") + I18n.getText("manager")%>'],
            ['0','<%=I18n.getText("security") + I18n.getText("level")%>']
        ]
    });
    opttypestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=opttypestr%>]
    });
    attachopttypestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=attachopttypestr%>]
    });
    wfopttypestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=wfopttypestr%>]
    });
    editviewstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=editviewstr%>]
    });
    readviewstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=readviewstr%>]
    });
    poststore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : []
    });
    userstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : []
    });
    orgstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : []
    });
    rolestore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : []
    });
    notifysettingstore = new Ext.data.SimpleStore({
        id:0,
        fields: ['value', 'text'],
        data : [<%=StringUtil.null2String(notifysettingstr)%>]
    });
    mainform = new Ext.FormPanel({
        region:'center',
        id:'mainform',
        frame:true,
        labelWidth :150,
        autoScroll:true,
        items :[
            {
                xtype:'hidden',
                name: 'id'
            } ,
            {
                xtype:'hidden',
                name: 'objid',
                value:'<%=objid%>'
            } ,
            {
                xtype:'hidden',
                name: 'betype',
                value:'<%=betype%>'
            } ,
            {
                xtype:'hidden',
                name: 'beworkflow',
                value:'<%=beworkflow%>'
            } ,
            {
                xtype:'hidden',
                name: 'tablename',
                value:'<%=tablename%>'
            } ,
            {
                xtype:'hidden',
                name: 'nodeid',
                value:'<%=nodeid%>'
            } ,
            {
                xtype:'hidden',
                name: 'formid',
                value:'<%=formid%>'
            } ,
            {   fieldLabel:"<%=I18n.getText("permission")%><%=I18n.getText("type")%>",
                xtype:'combo',
                allowBlank:false,
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:rightrangestore,
                value:'11',
                valueField:'value',
                displayField:'text',
                hiddenName: 'rightrange',
                hiddenName: 'rightrange',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("role")%><%=I18n.getText("range")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:yesorno,
                value:'0',
                valueField:'value',
                displayField:'text',
                hiddenName: 'rolerange',
                hiddenName: 'rolerange',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("org")%><%=I18n.getText("valuefrom")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:orgwherestore,
                value:'31',
                valueField:'value',
                displayField:'text',
                hiddenName: 'orgwhere',
                hiddenName: 'orgwhere',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("dimension")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead:true,
                mode:'local',
                forceSelection:true,
                triggerAction:'all',
                store:dimensionstore,
                value:'1',
                valueField:'value',
                displayField:'text',
                hiddenName:'dimension',
                hiddenName:'dimension',
                listeners:{ 'select':function () {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("user")%><%=I18n.getText("valuefrom")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:userwherestore,
                value:'26',
                valueField:'value',
                displayField:'text',
                hiddenName: 'userwhere',
                hiddenName: 'userwhere',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("post")%><%=I18n.getText("valuefrom")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:postwherestore,
                value:'59',
                valueField:'value',
                displayField:'text',
                hiddenName: 'postwhere',
                hiddenName: 'postwhere',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("post")%>",
                xtype:'xbrowserfield',
                url:'${ctx}/browser/browser.jsp?id=7',
                store:poststore,
                label:true,
                hiddenName: 'postid',
                name: 'postid'
            },
            {   fieldLabel:"<%=I18n.getText("user")%>",
                xtype:'xbrowserfield',
                url:'${ctx}/browser/browser.jsp?id=2',
                store:userstore,
                label:true,
                hiddenName: 'userids',
                name: 'userids'
            },
            {   fieldLabel:"<%=I18n.getText("org")%>",
                xtype:'xbrowserfield',
                url:'${ctx}/browser/browser.jsp?id=6',
                store:orgstore,
                label:true,
                hiddenName: 'orgid',
                name: 'orgid'
            },
            {   fieldLabel:"<%=I18n.getText("node")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:nodeforworkitemstore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'nodeforworkitem',
                hiddenName: 'nodeforworkitem',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("field")%>",
                xtype:'combo',
                width:300,
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:fieldstore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'fieldid',
                hiddenName: 'fieldid'
            },
            {   fieldLabel:"<%=I18n.getText("org")%><%=I18n.getText("range")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:orgrangestore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'orgrange',
                hiddenName: 'orgrange',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("role")%><%=I18n.getText("valuefrom")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:rolewherestore,
                value:'69',
                valueField:'value',
                displayField:'text',
                hiddenName: 'rolewhere',
                hiddenName: 'rolewhere',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("role")%>",
                xtype:'xbrowserfield',
                url:'${ctx}/browser/browser.jsp?id=13',
                store:rolestore,
                label:true,
                hiddenName: 'roleid',
                name: 'roleid'
            },
            {   fieldLabel:"<%=I18n.getText("role")%><%=I18n.getText("field")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:rolefieldstore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'rolefieldid',
                hiddenName: 'rolefieldid'
            },
            {   fieldLabel:"<%=I18n.getText("post")%><%=I18n.getText("range")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:postrangestore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'postrange',
                hiddenName: 'postrange',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("post")%><%=I18n.getText("level")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:postlevelstore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'postlevel',
                hiddenName: 'postlevel'
            },
            {   fieldLabel:"<%=I18n.getText("org")%><%=I18n.getText("type")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:orgtypestore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'orgtype',
                hiddenName: 'orgtype'
            },
            {   fieldLabel:"<%=I18n.getText("org")%><%=I18n.getText("manager")%>/<%=I18n.getText("security")+I18n.getText("level")%>",
                xtype:'combo',
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:beorgmanagerstore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'beorgmanager',
                hiddenName: 'beorgmanager',
                listeners:{ 'select':function() {
                    onChangeType();
                }
                }
            },
            {   fieldLabel:"<%=I18n.getText("minlevel")%>",
                maskRe : /^\d$/,
                xtype:'textfield',
                name: 'minlevel'
            } ,
            {   fieldLabel:"<%=I18n.getText("maxlevel")%>",
                maskRe : /^\d$/,
                xtype:'textfield',
                name: 'maxlevel'
            } ,
            {   fieldLabel:"<%=I18n.getText("opttype")%>",
                xtype:'combo',
                id:'opttypecombo',
                allowBlank:false,
                blankText:'<%=I18n.getText("mustfill")%>',
                typeAhead: true,
                mode:'local',
                forceSelection:true,
                triggerAction: 'all',
                store:opttypestore,
                valueField:'value',
                displayField:'text',
                hiddenName: 'opttype',
                hiddenName: 'opttype',
                listeners:{ 'select':function() {
                    onChangeOptType();
                }
                }

            }

        ]
    });
    formwin = new Ext.Window({
        title:'<%=I18n.getText("permission")%><%=I18n.getText("info")%>',
        layout:'border',
        closeAction:'hide',
        plain: true,
        modal :true,
        width:viewport.getSize().width * 0.9,
        height:viewport.getSize().height * 0.95,
        buttons: [
            {text     : '<%=I18n.getText("save")%>',
                handler  : function() {
                    thisvalue = mainform.form.findField('rightrange').getValue();
                    if (thisvalue == "11" && mainform.form.findField('userwhere').getValue() == "26") {
                        if (!mainform.form.findField('userids').getValue()) {
                            pop("请选择人员");
                            return;
                        }
                    } else if (thisvalue == "14" && !mainform.form.findField('orgid').hidden) {

                        if (!mainform.form.findField('orgid').getValue()) {
                            pop("请选择组织");
                            return;
                        }
                    } else if (thisvalue == "13" && mainform.form.findField('postwhere').getValue() == "59") {

                        if (!mainform.form.findField('postid').getValue()) {
                            pop("请选择岗位");
                            return;
                        }
                    }  else if (thisvalue == "14" && mainform.form.findField('orgwhere').getValue() == "31") {
                        if (!mainform.form.findField('orgid').getValue()) {
                            pop("请选择组织");
                            return;
                        }
                    } else if (thisvalue == "17" && mainform.form.findField('orgwhere').getValue() == "31" && mainform.form.findField('rolerange').getValue() == 1) {
                        if (!mainform.form.findField('roleid').getValue()) {
                            pop("请选择角色");
                            return;
                        }
                    } else if (thisvalue == "17" && mainform.form.findField('rolerange').getValue() == "1") {
                        if (!mainform.form.findField('roleid').getValue()) {
                            pop("请选择角色");
                            return;
                        }
                    }
                    //check other
                    if (!mainform.form.findField('orgrange').hidden) {
                        if (!mainform.form.findField('orgrange').getValue()) {
                            pop("请选择组织范围");
                            return;
                        }
                    }
                    if (!mainform.form.findField('postrange').hidden) {
                        if (!mainform.form.findField('postrange').getValue()) {
                            pop("请选择岗位范围");
                            return;
                        }
                    }
                    if (!mainform.form.findField('nodeforworkitem').hidden) {
                        if (!mainform.form.findField('nodeforworkitem').getValue()) {
                            pop("请选择节点");
                            return;
                        }
                    }
                    if (!mainform.form.findField('fieldid').hidden) {
                        if (!mainform.form.findField('fieldid').getValue()) {
                            pop("请选择字段");
                            return;
                        }
                    }
                    if (!mainform.form.findField('orgtype').hidden) {
                        if (!mainform.form.findField('orgtype').getValue()) {
                            pop("请选择组织类型");
                            return;
                        }
                    }
                    if (!mainform.form.findField('beorgmanager').hidden) {
                        if (!mainform.form.findField('beorgmanager').getValue()) {
                            pop("请选择组织经理/安全级别");
                            return;
                        }
                    }


                    if (!mainform.form.findField('postlevel').hidden) {
                        if (!mainform.form.findField('postlevel').getValue()) {
                            pop("请选择岗位级别");
                            return;
                        }
                    }
                    if (!mainform.form.findField('minlevel').hidden) {
                        if (!mainform.form.findField('minlevel').getValue() || !mainform.form.findField('maxlevel').getValue()) {
                            pop("请设置安全级别范围");
                            return;
                        }
                    }
                    mainform.form.submit({
                        url:'${ctx}/right.do?action=saveright',
                        success:function(f, a) {
                            store.load();
                            pop(a.result.msg);
                        },
                        failure:function(f, a) {
                            switch (a.failureType) {
                                case Ext.form.Action.CLIENT_INVALID :
                                    pop('<%=I18n.getText("validatefail")%>!', '<%=I18n.getText("error")%>', 5, 'cross');
                                    break;
                                case Ext.form.Action.CONNECT_FAILURE :
                                    pop('<%=I18n.getText("connectfail")%>!', '<%=I18n.getText("error")%>', 5, 'cross');
                                    break;
                                case Ext.form.Action.SERVER_INVALID :
                                    pop(a.result.msg, '<%=I18n.getText("error")%>', 5, 'cross');
                            }
                        }
                    });
                    formwin.hide();

                }
            },
            {
                text     : '<%=I18n.getText("close")%>',
                handler  : function() {
                    formwin.hide();
                }

            }
        ],
        items:[mainform]
    });
    formwin.render(Ext.getBody());
    store.load();
    onChangeType();
    var combo = Ext.getCmp("opttypecombo");
            var firstValue = opttypestore.getRange()[0].data.value;//获得第一项的值
        combo.setValue(firstValue);//选中
});

var Runner = function() {
    var f = function(pbar, count, cb) {

        return function() {
            doRefresh();
            if (currentCount >= count) {
                Ext.getCmp('S').enable();
                if (Ext.getCmp('C'))
                    Ext.getCmp('C').enable();
                if (Ext.getCmp('H') != null) {
                    Ext.getCmp('H').enable();
                }
                if (Ext.getCmp('G') != null) {
                    Ext.getCmp('G').enable();
                }
                clearInterval(refresstimer);
                cb();
            } else {
                var i = currentCount / count;
                //pbar.updateProgress(i, Math.round(100*i)+'%');
                pbar.updateProgress(i, currentCount + '/' + count);
            }
        };
    };
    return {
        run : function(pbar, count, cb) {
            var ms = 5000 / count;
            try {
                refresstimer = setInterval(f(pbar, count, cb), 1000);
            } catch(e) {
            }

        }
    }
}();
</script>
</head>

<body>

<div id="divSearch">
    <div id="pagemenubar"></div>
</div>
<div id="p1"></div>
<script language="javascript">
function onCreate() {
    this.formwin.show()
}
function onModify(id) {
    this.mainform.form.reset();
    this.mainform.load({
        url:'${ctx}/right.do?action=getright',
        params:{'id':id},
        success:function(f, a) {
        },
        failure:function(f, a) {
        }
    });

    this.formwin.show();
}

function recreate() {
    Ext.Ajax.request({
        url:'${ctx}/right.do?action=recreate',
        params:{objid:'<%=objid%>',betype:'<%=betype%>',tablename:'<%=tablename%>'},
        success: function(res) {
            if (Ext.getCmp('H'))
                Ext.getCmp('H').enable();
            if (Ext.getCmp('C'))
                Ext.getCmp('C').enable();
            if (Ext.getCmp('S'))
                Ext.getCmp('S').enable();
            pop('<%=I18n.getText("success")%>');

        }
    });
}
function getformfield(permtypeid) {
    fieldstore.load({params:{rightwhere:permtypeid,tablename:'<%=tablename%>'}})
}
function getrolefield(permtypeid) {
    rolefieldstore.load({params:{rightwhere:permtypeid,tablename:'<%=tablename%>'}})
}

function doRefactor(dowid, refactortable) {
    if (refactortable) {
        dwr.engine.setAsync(false);
        RightTransferService.refactor(dowid, refactortable, returnTotal);
        dwr.engine.setAsync(true);
    }
}
function doRequestRefactor(processid, refactortable) {
    if (refactortable) {
        dwr.engine.setAsync(false);
        RightTransferService.requestRefactor(processid, refactortable, returnTotal);
        dwr.engine.setAsync(true);
    }
}
function doRefactorWorkflowinfo(dowid) {
    dwr.engine.setAsync(false);
    RightTransferService.refactorWorkflowinfo(dowid, returnTotal);
    dwr.engine.setAsync(true);
}
function returnTotal(o) {
    total = o;
}

function returnCurrentCount(o) {
    currentCount = o
}
function doRefresh() {
    RightTransferService.getCurrentCount(returnCurrentCount);
}
function getCondition(formid,rightid) {
    var id;
    url="/workflow/transitionbrowser.jsp?formid="+formid+"&fromid="+rightid;
    try {
        id = showDialog("${ctx}" + url);
    } catch(e) {
    }
    if(id==null){

    }else{
        if(id.length&&id[0]==''){
            Ext.Ajax.request({
                        url:'${ctx}/wftransition.do?action=updateright',
                        params:{rightid:rightid,condition:'1'},
                        success: function(res) {
                            store.reload();
                        }
                    });
        }else
        store.reload();
    }


}
function onDelete() {
    if (selected.length == 0) {

        pop('', '<%=I18n.getText("selectConfirm")%>');
        return;
    }

    Ext.MessageBox.confirm('', '<%=I18n.getText("deleteConfirm")%>', function (btn, text) {
        if (btn == 'yes') {
            Ext.Ajax.request({
                url: '${ctx}/right.do?action=delete',
                params:{id:selected.toString(),objid:'<%=objid%>',beworkflow:'<%=beworkflow%>',betype:'<%=betype%>',tablename:'<%=tablename%>'},
                success: function() {
                    selected = [];
                    store.load();
                }
            });
        } else {
            selected = [];
            store.load();
        }
    });

}
function onChangeOptType(){
    thisvalue = mainform.form.findField('opttype').getValue();

}
function onChangeType() {

    thisvalue = mainform.form.findField('rightrange').getValue();
    hideField(mainform.form.findField('roleid'));
    hideField(mainform.form.findField('rolefieldid'));
    hideField(mainform.form.findField('postlevel'));
    hideField(mainform.form.findField('dimension'));
    mainform.form.setValues({'dimension':'1'});
    if (thisvalue == "11") {
        _sharetype = mainform.form.findField('userwhere').getValue();
        if (_sharetype == "26") {    //指定人员
            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            showField(mainform.form.findField('userwhere'));
            showField(mainform.form.findField('userids'));
            hideField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
            hideField(mainform.form.findField('dimension'));

        } else if (_sharetype == "27") {    //流程操作者相关
            //需要将当前工作流的节点信息读取到下拉框中。。。。
            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            showField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            hideField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            showField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
            hideField(mainform.form.findField('dimension'));

        } else {    //其他
            //需要读取不同的字段到选择框中。。。
            getformfield(_sharetype);
            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            showField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            hideField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            showField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
            hideField(mainform.form.findField('dimension'));
        }
    } else if (thisvalue == "13") {
        _sharetype = mainform.form.findField('postwhere').getValue();
        if (_sharetype == "59") {    //指定岗位

            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            showField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
            hideField(mainform.form.findField('dimension'));

        } else if (_sharetype == "61") {    //流程操作者相关

            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            showField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>

        } else {    //其他
            //需要读取不同的字段到选择框中。。。
            getformfield(_sharetype);
            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            showField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>
        }
    }
    else if (thisvalue == "12") {    //所有人+安全级别
        hideField(mainform.form.findField('rolerange'));
        hideField(mainform.form.findField('orgwhere'));
        hideField(mainform.form.findField('userwhere'));
        hideField(mainform.form.findField('userids'));
        hideField(mainform.form.findField('postwhere'));
        hideField(mainform.form.findField('postid'));
        hideField(mainform.form.findField('orgid'));
        hideField(mainform.form.findField('nodeforworkitem'));
        hideField(mainform.form.findField('fieldid'));
        hideField(mainform.form.findField('orgrange'));
        hideField(mainform.form.findField('rolewhere'));
        hideField(mainform.form.findField('postrange'));
        hideField(mainform.form.findField('orgtype'));
        hideField(mainform.form.findField('beorgmanager'));
        showField(mainform.form.findField('minlevel'));
        showField(mainform.form.findField('maxlevel'));
        hideField(mainform.form.findField('roleid'));
        hideField(mainform.form.findField('dimension'));
    }
    else if (thisvalue == "14") {    //组织单元+安全级别+作用域
        _sharetype = mainform.form.findField('orgwhere').getValue();
        if (_sharetype == "31") {    //指定组织单元
            hideField(mainform.form.findField('rolerange'));
            showField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            hideField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            showField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            showField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('dimension'));
            _orgSharetype = mainform.form.findField('orgrange').getValue();
            if (_orgSharetype == "36" || _orgSharetype == "37")
                hideField(mainform.form.findField('orgtype'));
            else
                showField(mainform.form.findField('orgtype'));
            showField(mainform.form.findField('beorgmanager'));
            _OrgManage = mainform.form.findField('beorgmanager').getValue();
            if (_OrgManage == 0) {
                showField(mainform.form.findField('minlevel'));
                showField(mainform.form.findField('maxlevel'));
            }
            else {
                hideField(mainform.form.findField('minlevel'));
                hideField(mainform.form.findField('maxlevel'));
            }
            hideField(mainform.form.findField('roleid'));

        } else if (_sharetype == "32") {    //流程节点操作者相关组织单元
            //需要将当前工作流的节点信息读取到下拉框中。。。。
            hideField(mainform.form.findField('rolerange'));
            showField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            hideField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            showField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            showField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>
            _orgSharetype = mainform.form.findField('orgrange').getValue();
            if (_orgSharetype == "36" || _orgSharetype == "37")
                hideField(mainform.form.findField('orgtype'));
            else
                showField(mainform.form.findField('orgtype'));
            showField(mainform.form.findField('beorgmanager'));
            _OrgManage = mainform.form.findField('beorgmanager').getValue();
            if (_OrgManage == 0) {
                showField(mainform.form.findField('minlevel'));
                showField(mainform.form.findField('maxlevel'));
            }
            else {
                hideField(mainform.form.findField('minlevel'));
                hideField(mainform.form.findField('maxlevel'));
            }
            hideField(mainform.form.findField('roleid'));
        } else {    //其他
            //需要读取不同的字段到选择框中。。。
            getformfield(_sharetype);
            hideField(mainform.form.findField('rolerange'));
            showField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            hideField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            showField(mainform.form.findField('fieldid'));
            showField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>
            _orgSharetype = mainform.form.findField('orgrange').getValue();
            if (_orgSharetype == "36" || _orgSharetype == "37")
                hideField(mainform.form.findField('orgtype'));
            else
                showField(mainform.form.findField('orgtype'));
            showField(mainform.form.findField('beorgmanager'));
            _OrgManage = mainform.form.findField('beorgmanager').getValue();
            if (_OrgManage == 0) {
                showField(mainform.form.findField('minlevel'));
                showField(mainform.form.findField('maxlevel'));
            }
            else {
                hideField(mainform.form.findField('minlevel'));
                hideField(mainform.form.findField('maxlevel'));
            }
            hideField(mainform.form.findField('roleid'));
        }
    }
    else if (thisvalue == "15") {     //人员+经理

        _sharetype = mainform.form.findField('postwhere').getValue();
        _usersharetype = mainform.form.findField('postrange').getValue();
        if (_sharetype == "59") {    //指定岗位
            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            showField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            showField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('dimension'));
            if (_usersharetype == "67")
                showField(mainform.form.findField('postlevel'));
            else
                hideField(mainform.form.findField('postlevel'));
            if (_usersharetype == "68")
                showField(mainform.form.findField('orgtype'));
            else
                hideField(mainform.form.findField('orgtype'));

            hideField(mainform.form.findField('beorgmanager'));

            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));

        } else if (_sharetype == "61") {    //流程操作者相关

            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            showField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            showField(mainform.form.findField('postrange'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>
            if (_usersharetype == "67")
                showField(mainform.form.findField('postlevel'));
            else
                hideField(mainform.form.findField('postlevel'));
            if (_usersharetype == "68")
                showField(mainform.form.findField('orgtype'));
            else
                hideField(mainform.form.findField('orgtype'));

            hideField(mainform.form.findField('beorgmanager'));

            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
        } else {    //其他
            //需要读取不同的字段到选择框中。。。
            getformfield(_sharetype);
            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            showField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            showField(mainform.form.findField('postrange'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>
            if (_usersharetype == "67")
                showField(mainform.form.findField('postlevel'));
            else
                hideField(mainform.form.findField('postlevel'));
            if (_usersharetype == "68")
                showField(mainform.form.findField('orgtype'));
            else
                hideField(mainform.form.findField('orgtype'));

            hideField(mainform.form.findField('beorgmanager'));

            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
        }
    }
    else if (thisvalue == "16") {     //人员+经理
        _sharetype = mainform.form.findField('postwhere').getValue();
        if (_sharetype == "59") {    //指定岗位

            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            showField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            showField(mainform.form.findField('postlevel'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));

            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
            hideField(mainform.form.findField('dimension'));
        } else if (_sharetype == "61") {    //流程操作者相关

            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            showField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            showField(mainform.form.findField('postlevel'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>

            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
        } else {    //其他
            //需要读取不同的字段到选择框中。。。
            getformfield(_sharetype);
            hideField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            showField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            showField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            hideField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            showField(mainform.form.findField('postlevel'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
        <%if(!beone){%>
            showField(mainform.form.findField('dimension'));
        <%}%>

            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));
            hideField(mainform.form.findField('roleid'));
        }
    }
    else if (thisvalue == "17") { //组织单元+角色+作用域

        _roletype = mainform.form.findField('rolerange').getValue();
        _roletype2 = mainform.form.findField('rolewhere').getValue();
        if (_roletype2 == "70") {
            _sharetype = mainform.form.findField('rolewhere').getValue();
            getrolefield(_sharetype);
            hideField(mainform.form.findField('roleid'));
            showField(mainform.form.findField('rolefieldid'));
        } else {
            showField(mainform.form.findField('roleid'));
            hideField(mainform.form.findField('rolefieldid'));
        }
        if (_roletype == 0) {

            showField(mainform.form.findField('rolerange'));
            hideField(mainform.form.findField('orgwhere'));
            hideField(mainform.form.findField('userwhere'));
            hideField(mainform.form.findField('userids'));
            hideField(mainform.form.findField('postwhere'));
            hideField(mainform.form.findField('postid'));
            hideField(mainform.form.findField('orgid'));
            hideField(mainform.form.findField('nodeforworkitem'));
            hideField(mainform.form.findField('fieldid'));
            hideField(mainform.form.findField('orgrange'));
            showField(mainform.form.findField('rolewhere'));
            hideField(mainform.form.findField('postrange'));
            hideField(mainform.form.findField('orgtype'));
            hideField(mainform.form.findField('beorgmanager'));
            hideField(mainform.form.findField('dimension'));

            hideField(mainform.form.findField('minlevel'));
            hideField(mainform.form.findField('maxlevel'));

        } else {
            _sharetype = mainform.form.findField('orgwhere').getValue();
            if (_sharetype == "31") {    //指定组织单元

                showField(mainform.form.findField('rolerange'));
                showField(mainform.form.findField('orgwhere'));
                hideField(mainform.form.findField('userwhere'));
                hideField(mainform.form.findField('userids'));
                hideField(mainform.form.findField('postwhere'));
                hideField(mainform.form.findField('postid'));
                showField(mainform.form.findField('orgid'));
                hideField(mainform.form.findField('nodeforworkitem'));
                hideField(mainform.form.findField('fieldid'));
                hideField(mainform.form.findField('orgrange'));
                showField(mainform.form.findField('rolewhere'));
                hideField(mainform.form.findField('postrange'));
                hideField(mainform.form.findField('orgtype'));
                hideField(mainform.form.findField('beorgmanager'));
                hideField(mainform.form.findField('dimension'));

                hideField(mainform.form.findField('minlevel'));
                hideField(mainform.form.findField('maxlevel'));

            } else if (_sharetype == "32") {    //流程节点操作者相关组织单元


                //需要将当前工作流的节点信息读取到下拉框中。。。。


                showField(mainform.form.findField('rolerange'));
                showField(mainform.form.findField('orgwhere'));
                hideField(mainform.form.findField('userwhere'));
                hideField(mainform.form.findField('userids'));
                hideField(mainform.form.findField('postwhere'));
                hideField(mainform.form.findField('postid'));
                hideField(mainform.form.findField('orgid'));
                showField(mainform.form.findField('nodeforworkitem'));
                hideField(mainform.form.findField('fieldid'));
                hideField(mainform.form.findField('orgrange'));
                showField(mainform.form.findField('rolewhere'));
                hideField(mainform.form.findField('postrange'));
                hideField(mainform.form.findField('orgtype'));
                hideField(mainform.form.findField('beorgmanager'));
            <%if(!beone){%>
                showField(mainform.form.findField('dimension'));
            <%}%>

                hideField(mainform.form.findField('minlevel'));
                hideField(mainform.form.findField('maxlevel'));

            } else {    //其他
                //需要读取不同的字段到选择框中。。。

                getformfield(_sharetype);
                showField(mainform.form.findField('rolerange'));
                showField(mainform.form.findField('orgwhere'));
                hideField(mainform.form.findField('userwhere'));
                hideField(mainform.form.findField('userids'));
                hideField(mainform.form.findField('postwhere'));
                hideField(mainform.form.findField('postid'));
                hideField(mainform.form.findField('orgid'));
                hideField(mainform.form.findField('nodeforworkitem'));
                showField(mainform.form.findField('fieldid'));
                hideField(mainform.form.findField('orgrange'));
                showField(mainform.form.findField('rolewhere'));
                hideField(mainform.form.findField('postrange'));
                hideField(mainform.form.findField('orgtype'));
                hideField(mainform.form.findField('beorgmanager'));
            <%if(!beone){%>
                showField(mainform.form.findField('dimension'));
            <%}%>

                hideField(mainform.form.findField('minlevel'));
                hideField(mainform.form.findField('maxlevel'));
            }

        }
    }

}

</script>
</BODY>
</HTML>